package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.SysRoleDao;
import com.bestv.search.common.model.SysRole;

import java.util.List;

public class SysRoleHibernate extends GenericDaoHibernate<SysRole, Long> implements SysRoleDao {

    public SysRoleHibernate() {
        super(SysRole.class);
    }

    @Override
    public SysRole getRoleByID(Long id) {
        return super.get(id);
    }

    @Override
    public List<SysRole> getRoles() {
        return super.getAll();
    }

    @SuppressWarnings("unchecked")
    @Override
    public SysRole getRolesByName(String name) {
        List<SysRole> roles = super.getHibernateTemplate().find("from SysRole r where r.name = ?", name);
        if (roles != null && roles.size() > 0)
            return roles.get(0);
        else
            return null;
    }

    @Override
    public SysRole saveRole(SysRole role) {
        return super.save(role);
    }
}
